<div class="stories container">
	
	<h2><?php echo __d('admin', 'Create Story'); ?></h2>
	
<?php

$formOptions = array (
	'inputDefaults' => array (
		'div' => array('class' => 'form-group'),
		'class' => 'form-control input-lg'
	)
);

$formElements = array (
	'id' => '',
	'title' => '',
	'body' => array(
		'after' => $this->element('wysiwyg', array('el' => 'contentEditor', 'value' => '')),
		'style' => 'width:0;height:0;opacity:0;position:absolute;'
	),
	'tags' => array(
		'before' => '<span class="glyphicon glyphicon-tags"></span> ',
		'class' => 'form-control input-sm'
	)
);

?>
	
	<?php echo $this->Form->create('Story', $formOptions); ?>
		<div class="row row-offcanvas row-offcanvas-right">

			<div class="col-xs-12 col-sm-8">
				<?php
				foreach($formElements as $field => $options) {
					echo $this->Form->input($field, (array)$options) . "\n";
				}
				echo $this->Form->submit(__d('admin', 'Publish'), array('class' => 'btn btn-primary'));
				?>
			</div>

			<div class="col-xs-12 col-sm-4 sidebar-offcanvas" id="sidebar" role="navigation">
				<div class="panel panel-default">
					<div class="panel-heading"><b>Publish Status</b></div>
					<div class="panel-body">
						<?php echo $this->Form->input('status', array(
							'label' => false,
							'class' => 'form-control input-sm',
							'options' => array(
								Story::PUBLISHED => __d('admin', 'publish'),
								Story::DRAFT => __d('admin', 'draft')
							)
						)); ?>
						<p>
							<a href="#" class="btn btn-default">Preview</a>
						</p>
					</div>
				</div>
				<div class="panel panel-default">
					<div class="panel-heading"><b><?php echo __d('admin', 'Author'); ?></b></div>
					<div class="panel-body">
						<div class="form-group">
							<?php echo $this->Form->input('author_id', array (
								'label' => false,
								'class' => 'form-control input-sm'
							)); ?>
						</div>
						<p>
							<a href="#ModalCreateAuthor" class="btn btn-link" data-toggle="modal">
								<span class="glyphicon glyphicon-plus"></span> <?php echo __d('admin', 'Add New Author'); ?>
							</a>
						</p>
					</div>
				</div>
				<div class="panel panel-default">
					<div class="panel-heading"><b><?php echo __d('admin', 'Category'); ?></b></div>
					<div class="panel-body">
						<div class="form-group">
							<?php echo $this->Form->input('category_id', array (
								'label' => false,
								'class' => 'form-control input-sm',
								'empty' => __d('admin', 'Uncategorized'),
								'escape' => false
							)); ?>
						</div>
						<p>
							<a href="#ModalCreateCategory" class="btn btn-link" data-toggle="modal"><span class="glyphicon glyphicon-plus"></span> Add New Category</a>
						</p>
					</div>
				</div>
			</div>
		</div>
	<?php echo $this->Form->end(); ?>
</div>

<?php 
	// dialogs
	echo $this->element('Authors/dialog_create_author');
	echo $this->element('Stories/dialog_create_category');
?>

<script>
	$( document ).ready(function() {
		$( "#StoryCreateForm, #StoryEditForm" ).submit(function() {
			// get data from the WYSIWYG editor.
			$( "#StoryBody" ).val( $("#contentEditor").html() );
		});
	});
</script>